package org.syncsoft.overalt.common.api;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * program configuration
 * 
 * @author tptfc
 *
 */
public class Configuration {
	private static Properties properties;
	private static ApplicationUser userInSession;
	
	static {
		try {
			setProperties(new Properties());
			InputStream stream = Configuration.class.getClassLoader().getResourceAsStream("overalt.properties");
			getProperties().load(stream);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 
	 * @return URL server domain 
	 */
	public static String getUrlDomain() {
		return getProperty("overalt.url.domain");
	}

	/**
	 * 
	 * @return URL server connection
	 */
	public static String getUrlConnection() {
		return getUrlDomain() + getProperty("overalt.url.connection");
	}
	
	/**
	 * 
	 * @return login query parameter name to use in login action
	 */
	public static String getLoginQueryParameterName() {
		return getProperty("overalt.login.queryParameterName");
	}
	
	/**
	 * 
	 * @return password query parameter name to use in login action
	 */
	public static String getPasswordQueryParameterName() {
		return getProperty("overalt.password.queryParameterName");
	}
	
	/**
	 * 
	 * @return return the kind to encode the parameters
	 */
	public static String getDefaultEncodeParameters() {
		return getProperty("overalt.default.encode.parameters");
	}
	
	/**
	 * 
	 * @return return the max pool connections
	 */
	public static Integer getMaxPoolConnections() {
		return Integer.parseInt(getProperty("overalt.max.pool.connections"));
	}
	
	/**
	 * 
	 * @return return the document title entity name
	 */
	public static String getDocumentCodeEntityName() {
		return getProperty("overalt.document.code");
	}
	
	/**
	 * 
	 * @return return the document title entity name
	 */
	public static String getDocumentVersionedEntityName() {
		return getProperty("overalt.document.versioned");
	}
	
	/**
	 * 
	 * @return return the document title entity name
	 */
	public static String getDocumentCommentEntityName() {
		return getProperty("overalt.document.comment");
	}
	
	/**
	 * 
	 * @return return the document title entity name
	 */
	public static String getDocumentTitleEntityName() {
		return getProperty("overalt.document.title");
	}

	/**
	 * 
	 * @return return the document description entity name
	 */
	public static String getDocumentDescriptionEntityName() {
		return getProperty("overalt.document.description");
	}

	/**
	 * 
	 * @return return the document tags entity name
	 */
	public static String getDocumentTagsEntityName() {
		return getProperty("overalt.document.tags");
	}
	
	/**
	 * 
	 * @return return the document communities entity name
	 */
	public static String getDocumentCommunitiesEntityName() {
		return getProperty("overalt.document.communities");
	}
	
	/**
	 * 
	 * @return return the document policy entity name
	 */
	public static String getDocumentPolicyEntityName() {
		return getProperty("overalt.document.policy");
	}

	/**
	 * 
	 * @return return the document file entity name
	 */
	public static String getDocumentFileEntityName() {
		return getProperty("overalt.document.file");
	}
	
	/**
	 * 
	 * @return
	 */
	public static String getMergeExecutable(){
		return getProperty("overalt.merge.execute");
	}
	
	/**
	 * @precondition getApplicationUser() != null
	 * @return
	 */
	public static ApplicationUser getUserInSession() {
		return Configuration.userInSession;
	}

	/**
	 * 
	 * @param userInSession
	 */
	public static void setUserInSession(ApplicationUser userInSession) {
		Configuration.userInSession = userInSession;
	}
	
	private static String getProperty(String property) {
		return getProperties().getProperty(property);
	}
	
	//	GETs AND SETs
	protected static Properties getProperties() {
		return properties;
	}
	protected static void setProperties(Properties properties) {
		Configuration.properties = properties;
	}
}
